<template>
  <div class="theme">
    <!-- 退出 -->
    <img class="exitBtn" @click="clickExitBtn" src="../assets/img/exitBtn.png" alt="">
    <div class="mainBox">
        <template v-if="isDownload && isPrinter">
          <!-- 打印及下载都操作过了 -->
          <div class="text" v-if="lastOperation == 'isDownload'">
              <div>请在微信公众号获取您的照片,</div>
              <div> 如未获取，请联系客服人员帮助。</div>
          </div>
          <div class="text" v-if="lastOperation == 'isPrinter'">
              <div>您的照片打印成功，</div>
              <div>请取走您的照片~</div>
          </div>
          <div class="photosBtns">
            <div class="rightBtn bths" @click="continuePhotos">
                <div>继续拍照</div>
            </div>
          </div>
        </template>
        <template v-else>
          <template v-if="isDownload">
            <!-- 只下载过 -->
            <div class="text">
                <div>请在微信公众号获取您的照片,</div>
                <div> 如未获取，请联系客服人员帮助。</div>
            </div>
            <div class="photosBtns">
              <div class="leftBtn bths" @click="clickPrint">
                  <div>打印照片</div>
              </div>
              <div class="rightBtn bths" @click="continuePhotos">
                  <div>继续拍照</div>
              </div>
            </div>
          </template>
          <template v-if="isPrinter">
            <!-- 只打印过 -->
            <div class="text">
                <div>您的照片打印成功，</div>
                <div>请取走您的照片~</div>
            </div>
            <div class="photosBtns">
              <div class="leftBtn bths" @click="clickDownload">
                  <div>下载照片</div>
              </div>
              <div class="rightBtn bths" @click="continuePhotos">
                  <div>继续拍照</div>
              </div>
            </div>
          </template>
        </template>
    </div>
    <div class="conlist" v-rollY>
      <div class="items" v-for="(item,index) in list" :key="index" @click="toGoods(item)">
        <div class="imgBox">
          <img :src="item.imgUrl" alt="">
        </div>
        <div class="nameBox">{{item.name}}</div>
      </div>
    </div>

    <!-- 公众号弹框 -->
    <officialAccount :isShow.sync="officialAccountShow" @scanCodeEnd="scanCodeEnd"></officialAccount>
    <!-- 打印弹框 -->
    <printer :isShow.sync="printShow" @printEnd="printEnd"></printer>
    <!-- 退出确认弹框 -->
    <exitConfirmation :isShow.sync="exitShow"></exitConfirmation>
  </div>
</template>

<script>
import {mapState,mapMutations} from 'vuex'
import officialAccount from '../components/officialAccount.vue'
import printer from '../components/printer.vue'
import exitConfirmation from '../components/exitConfirmation.vue'
import {modelList} from '../server/api'
export default {
  components:{
    officialAccount,
    printer,
    exitConfirmation
  },
  computed:{
    ...mapState([
      //必须带引号
      'isDownload',
      'isPrinter',
      'lastOperation',
    ])
  },
  data(){
    return {
      list:[],
      // 公众号弹框
      officialAccountShow:false,
      // 打印弹框
      printShow:false,
      // 退出弹框
      exitShow:false,
    }
  },
  methods:{
    ...mapMutations([
      'setCommonData'
    ]),
    // 点击下载
    clickDownload(){
      this.officialAccountShow = true;
    },
    // 公众号弹框扫码完毕
    scanCodeEnd(){
      this.setCommonData({
          key:'isDownload',
          value:true,
      })
      this.setCommonData({
          key:'lastOperation',
          value:'isDownload',
      })
    },
    // 点击打印
    clickPrint(){
      // 弹框显示
      this.printShow = true;
    },
    // 打印结束
    printEnd(){
      this.setCommonData({
          key:'isPrinter',
          value:true,
      })
      this.setCommonData({
          key:'lastOperation',
          value:'isPrinter',
      })
    },
    // 点击退出
    clickExitBtn(){
        this.exitShow = true;
    },
    // 点击继续拍照
    continuePhotos(){
      this.$router.push('/theme')
    },
    // 获取模型列表
    getmodelList(){
      modelList().then(res=>{
        console.log(res);
        this.list = res.data;
      }).catch(err=>{

      })
    },
    // 跳转商品
    toGoods(data){
      console.log(data)
      let isClick = document.getElementsByClassName('conlist')[0].getAttribute('data-flag');
      if(isClick === 'true'){
        this.$router.push('/goodList?modelId='+data.id+'&title='+data.name)
      }
    },
  },
  mounted(){
    this.getmodelList();
  }
}
</script>

<style lang="less" scoped>
.theme{
  width: 100%;
  height: 1920px;
  background-image: url('../assets/img/bgImg.png');
  background-size: 100% 1920px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  .exitBtn{
    width: 94px;
    height: 94px;
    position: fixed;
    left: 52px;
    top: 46px;
  }
  .mainBox{
    margin-top: 250px;
    .text{
        font-size: 48px;
        color: #FFFFFF;
        text-align: center;
    }
    .photosBtns{
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 80px;
        .leftBtn{
            // background-image: url('../assets/img/leftBtn.png');
            background-size: 100% 101px;
            margin-right: 86px;
        }
        .rightBtn{
            // background-image: url('../assets/img/rightBtn.png');
            background-size: 100% 101px;
        }
        .bths{
            width: 240px;
            height: 101px;
            font-size: 32px;
            color: #FFFFFF;
            text-align: center;
            line-height: 101px;
            display: flex;
            align-items: center;
            justify-content: center;
            .icons{
                font-size: 40px;
                font-weight: bold;
                margin-right: 10px;
            }
        }
    }
  }
  .conlist{
    width: 100%;
    height: auto;
    padding: 0 120px 80px;
    box-sizing: border-box;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-top: 120px;
    .items{
      width: 356px;
      height: auto;
      margin-top: 60px;
      &:nth-child(-n+2){
        margin-top: 0;
      }
      .imgBox{
        width: 100%;
        height: 492px;
        // border-image: linear-gradient(180deg, #CB6AFF 0%, #3FC8E9 24.5%, #7875FC 51.5%, #FF67EF 74%, #FFCA99 100%);
        border: 4px solid transparent;
        border-image: linear-gradient(180deg, #CB6AFF, #FFCA99) 1 1 round;
        box-shadow: 8px 10px 10px 0px #5D009580;
        box-sizing: border-box;
        img{
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
      .nameBox{
        width: 100%;
        font-size: 48px;
        color: #FFFFFF;
        text-align: center;
        margin-top: 10px;
      }
    }
  }
}
</style>